Skip to content

Optimize QueryIndex key comparison in matching hot path#1243

Merged
brharrington merged 2 commits into
Netflix:mainfrom
brharrington:query-index-name-compare-opt
Jun 4, 2026
Merged

Optimize QueryIndex key comparison in matching hot path#1243
brharrington merged 2 commits into
Netflix:mainfrom
brharrington:query-index-name-compare-opt

Conversation

@brharrington

Copy link
Copy Markdown
Contributor

forEachMatch compared every id key against a node's key via compare(), which did up to two "name".equals() checks plus a compareTo on each call. Since a node's key is fixed, hoist the "name" check out of the per-tag loop, and skip the name-first special-casing entirely for tag positions >= 1 (only position 0 holds the synthesized name key, and the tag list is sorted so the special-casing is unnecessary there).

Adds a QueryIndexMatch JMH benchmark exercising the LWC bridge matching path (5k subscription queries x 200 ids). Measured on JDK 25:

current 144.46 us/op
hoist 137.88 us/op
+peel 132.67 us/op (~8% faster, no allocation change)

forEachMatch compared every id key against a node's key via compare(),
which did up to two "name".equals() checks plus a compareTo on each
call. Since a node's key is fixed, hoist the "name" check out of the
per-tag loop, and skip the name-first special-casing entirely for tag
positions >= 1 (only position 0 holds the synthesized name key, and the
tag list is sorted so the special-casing is unnecessary there).

Adds a QueryIndexMatch JMH benchmark exercising the LWC bridge matching
path (5k subscription queries x 200 ids). Measured on JDK 25:

  current  144.46 us/op
  hoist    137.88 us/op
  +peel    132.67 us/op  (~8% faster, no allocation change)
@brharrington brharrington added this to the 1.9.10 milestone Jun 4, 2026
Inlining the position-based comparison as a nested ternary in
forEachMatch pushed its NPath complexity to 331 (threshold 200).
Extract the comparison into a compareTagKey helper, moving the
branching out of forEachMatch. No behavior change.
@brharrington brharrington merged commit 71be5ba into Netflix:main Jun 4, 2026
1 check passed
@brharrington brharrington deleted the query-index-name-compare-opt branch June 4, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant